package com.shenhonghui.twins.utils;

import ohos.app.Context;

public class WindowUtil {
    /**
     * 1vp 约等于 160dpi 屏幕密度设备上的 1px
     * context.getResourceManager().getDeviceCapability().width，返回的数值单位是vp
     * context.getResourceManager().getDeviceCapability().screenDensity  屏幕密度
     * @param context
     * @return 像素px
     */
    public static int getWindowWidth(Context context) {
        return context.getResourceManager().getDeviceCapability().width * context.getResourceManager().getDeviceCapability().screenDensity / 160;
    }

    /**
     * 1vp 约等于 160dpi 屏幕密度设备上的 1px
     * context.getResourceManager().getDeviceCapability().height，返回的数值单位是vp
     * context.getResourceManager().getDeviceCapability().screenDensity  屏幕密度
     * @param context
     * @return px
     */
    public static int getWindowHeight(Context context) {
        return context.getResourceManager().getDeviceCapability().height * context.getResourceManager().getDeviceCapability().screenDensity / 160;
    }
}
